package com.jianyun.jyzs.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jianyun.jyzs.R;
import com.jianyun.jyzs.adapter.EngMessageAdapter;
import com.jianyun.jyzs.bean.EdMessageBean;
import com.jianyun.jyzs.bean.MessageData;
import com.jianyun.jyzs.dao.EnginnerMsgDao;
import com.jianyun.jyzs.http.Api;
import com.jianyun.jyzs.http.RetrofitHelper;
import com.jianyun.jyzs.utils.LocalSp;
import com.jianyun.jyzs.utils.LoginCache;
import com.jianyun.jyzs.utils.UtilsStyle;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * Created by yangshijun on 2018/5/31.
 * 工程动态消息列表
 */

public class EDMessageActivity extends AppCompatActivity {
    @BindView(R.id.topBack)
    ImageView topBack;
    @BindView(R.id.topText)
    TextView topText;
    @BindView(R.id.tv_checked)
    TextView tvChecked;
    @BindView(R.id.tv_update)
    TextView tvUpdate;
    @BindView(R.id.iv_more)
    ImageView ivMore;
    @BindView(R.id.iv_moreLinearLayout)
    LinearLayout ivMoreLinearLayout;
    @BindView(R.id.topCreat)
    LinearLayout topCreat;
    @BindView(R.id.iv_single)
    ImageView ivSingle;
    @BindView(R.id.iv_group)
    ImageView ivGroup;
    @BindView(R.id.topChatDetail)
    LinearLayout topChatDetail;
    @BindView(R.id.topId)
    RelativeLayout topId;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private EngMessageAdapter adapter;
    private EnginnerMsgDao msgDao;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        UtilsStyle.setStatusBarMode(this,true);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_engineer_message);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        initView();
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        List<MessageData> list = new ArrayList<>();
        adapter = new EngMessageAdapter(this, list);
        recyclerView.setAdapter(adapter);
        initServiceData();
    }

    private void initServiceData() {
        String userId = LoginCache.getInstance().getUserInfo().getUserId();
        msgDao = new EnginnerMsgDao(this);
        List<MessageData> list = msgDao.getEnginmsgByUserId(userId);
        if (list != null) {
            adapter.setList(list);
        }
    }

    private void initView() {
        topBack.setVisibility(View.VISIBLE);
        topText.setText("消息列表");
        tvChecked.setVisibility(View.VISIBLE);
        tvChecked.setText("清空");
    }

    @OnClick({R.id.topBack, R.id.tv_checked})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.topBack:
                finish();
                break;
            case R.id.tv_checked:
                msgDao.delete();

                adapter.setList(null);
                break;

        }
    }
}
